import { ref, reactive } from 'vue';
import { http } from '@/utils/http/index.js'

/**
 * 分页钩子
 */
export default (pageSize, url) => {
  const listLoading = ref(false)
  const pager = reactive({
    total: 0,
    pageSize,
    pageIndex: 1
  })

  const proxyFun = (params) => {
    return new Promise(resolve => {
      listLoading.value = true
      http.$POST(url, { ...params, pageSize: pager.pageSize, pageIndex: pager.pageIndex }).then(res => {
        if (res.isError) return
        resolve(res)
        pager.total = res.result.countAll
      }).finally(() => listLoading.value = false)
    })

  }
  return { pager, listLoading, proxyFun }
}

